package com.sgj.controller;

import com.sgj.enums.GobalEnum;
import com.sgj.service.UserService;
import com.sgj.utils.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 沈国纪
 * @date 2021/7/5 13:14
 */
@RestController
@RequestMapping("passport")
public class PassportController {

	@Resource
	private UserService userService;

	@GetMapping("/usernameIsExist")
	public R usernameIsExist(@RequestParam String username) {
		// 判断用户名是否为空
		if (StringUtils.isBlank(username)) {
			return R.error(GobalEnum.USER_NULL.getCode(), GobalEnum.USER_NULL.getMessage());
		}
		// 查找注册过的用户是否已经存在
		boolean isExist = userService.queryUsernameIsExist(username);
		if (isExist) {
			return R.error(GobalEnum.USER_EXIST.getCode(), GobalEnum.USER_EXIST.getMessage());
		}
		// 请求成功，用户名没有重复
		return R.ok(GobalEnum.USER_EXIST.getCode(), GobalEnum.USER_EXIST.getMessage());
	}

}